package com.base.commonlib.utils;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by arvin on 2018/11/15.
 */

public class MultiFileUtil {

    public static void showPdf(Context context, String path) {
        File file = new File(path);
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = Uri.fromFile(file);
        intent.setDataAndType(uri, "application/pdf");
        try {
            context.startActivity(intent);
        } catch (Exception e) {

        }


    }

    public static void showWord(Context context, String path) {
        File file = new File(path);
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = Uri.fromFile(file);
        intent.setDataAndType(uri, "application/msword");

        try {
            context.startActivity(intent);
        } catch (Exception e) {

        }
    }


    public static void showExcel(Context context, String path) {
        File file = new File(path);
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = Uri.fromFile(file);
        intent.setDataAndType(uri, "application/vnd.ms-excel");
        try {
            context.startActivity(intent);
        } catch (Exception e) {

        }
    }

//    public static void ShowPic(Context context, List<ImageItem> pics) {
//        CustomImgDialog customImgDialog = new CustomImgDialog(context, com.arvin.imagepicker.R.style.CustomDialog_fill, pics, false, 0);
//        customImgDialog.show();
//    }
//
//
//
//    public static void open(Context context, String path) {
//        if (TextUtils.isEmpty(path)) {
//            return;
//        }
//
//        if (path.contains(".jpg") || path.contains(".jpeg") || path.contains(".png")) {
//            ArrayList<ImageItem> imageItems = new ArrayList<>();
//            imageItems.add(new ImageItem(path,""));
//            ShowPic(context, imageItems);
//
//        } else if (path.contains(".doc") || path.contains(".docx")) {
//            showWord(context, path);
//        } else if (path.contains(".xls") || path.contains(".xlsx")) {
//            showExcel(context, path);
//        } else if (path.contains(".pdf")) {
//            showPdf(context, path);
//        }
//
//
//    }

}
